package loupan_swiper_dao

import (
	database "hft/Database"
	"hft/Database/admin"
	"hft/global"
	"hft/test"
	"hft/test/mi/loupan_swiper/loupan_swiper_model"
	"hft/test/mi/loupan_swiper/loupan_swiper_utils"
	"strings"
)

func MiS() {
	var list []*admin.LouPan
	global.OC_DB.Find(&list)
	MiLouPanSwiper(list)
}

func MiLouPanSwiper(louList []*admin.LouPan) {
	var a1 = make([]*loupan_swiper_model.LouPanSwiperModel, 0)
	var a2 = make([]*loupan_swiper_model.LouPanSwiperModel, 0)
	var unionA = make([]*loupan_swiper_model.LouPanSwiperModel, 0)
	test.Sql().Table("flw_album").Find(&a1)
	test.Sql().Table("flw_album2").Find(&a2)
	unionA = append(unionA, a1...)
	unionA = append(unionA, a2...)
	for _, v := range unionA {
		if loupan_swiper_utils.IsContainThisLou(louList, uint(v.PID)) {
			var cname string
			switch v.Cate {
			case 1:
				cname = "效果图"
			case 2:
				cname = "户型图"
			case 3:
				cname = "区位图"
			case 4:
				cname = "样板间"
			case 5:
				cname = "环境规划图"
			case 6:
				cname = "视频"
			}
			var cover string
			var url string
			if !strings.Contains(v.Cpic, "mp4") {
				url = v.Cpic
			} else {
				cover = v.Cpic + "?x-oss-process=video/snapshot,t_5000,f_jpg,m_fast"
				url = v.Cpic
			}
			var item = &admin.LouPanSwiper{
				Category:     v.Cate,
				Cover:        cover,
				Base:         database.Base{Sort: v.Csort},
				CategoryName: cname,
				LouPanID:     v.PID,
				Url:          url,
				Title:        "",
			}
			global.OC_DB.Create(&item)
		}

	}
}
